<?php
class categories {
    function set_page($new_page) {
        $this->pageid = $new_page;
        return $this->pageid;
    }

    function set_id($new_id) {
        $this->id = $new_id;
        return $this->id;
    }

    function get_catGroups() {
        $connect = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        $query = $connect->query("SELECT category FROM ".$prefix."posts WHERE draft = '0' GROUP BY category ORDER BY id DESC");
        $numrows = $query->num_rows;

        while($row = $query->fetch_object()) {
            $countCat = $connect->query("SELECT id FROM ".$prefix."posts WHERE category = '".$row->category."' AND draft = '0'");
            $countRows = $countCat->num_rows;

            $this->categories[] = array(
                "category" => $row->category,
                "count" => $countRows
            );
        }
        return $this->categories;
        $countCat->close();
        $query->close();
        $connect->close();
    }
}
?>
